<?php
/**
 * @Name: NodeController.php
 * @Author: yashuai
 */

namespace App\Http\Controllers\Rbac;

use App\Http\Logic\Rbac\NodeLogic;
use App\Http\Search\Rbac\NodeSearch;
use App\Http\Requests\Rbac\NodeIDRequest;
use App\Http\Requests\Rbac\NodeSaveRequest;

class NodeController
{

    /**
     * 列表
     * @return \Illuminate\Http\JsonResponse
     */
    public function index()
    {
        $result = NodeSearch::instance()->index();
        return _success($result);
    }

    /**
     * 添加
     * @param NodeSaveRequest $request
     * @return \Illuminate\Http\JsonResponse
     * @throws \App\Exceptions\ApiException
     */
    public function create(NodeSaveRequest $request)
    {
        $result = NodeLogic::instance($request->getValidationData())->create();
        return _success($result);
    }

    /**
     * 编辑
     * @param NodeSaveRequest $request
     * @return \Illuminate\Http\JsonResponse
     * @throws \App\Exceptions\ApiException
     */
    public function update(NodeSaveRequest $request)
    {
        $validator = [
            'NodeID' => 'required|integer'
        ];
        $result = NodeLogic::instance($request->getValidationData($validator))->update();
        return _success($result);
    }

    /**
     * 删除
     * @param NodeSaveRequest $request
     * @return \Illuminate\Http\JsonResponse
     * @throws \App\Exceptions\ApiException
     */
    public function delete(NodeIDRequest $request)
    {
        $result = NodeLogic::instance($request->getValidationData())->delete();
        return _success($result);
    }

}
